﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.Restaurant
{
    public class RestaurantPresenter : Presenter<IRestaurantView>
    {
        public RestaurantPresenter(IRestaurantView view)
            : base(view)
        {
        }

        public void Display(string restaurantId)
        {
            if (restaurantId == null) return;

            var restaurant = Model.GetRestaurant(restaurantId);

            View.RestaurantID = restaurant.RestaurantID;
            View.RestaurantCode = restaurant.RestaurantCode;
            View.RestaurantName = restaurant.RestaurantName;
            View.Address = restaurant.Address;
            View.PhoneNumber = restaurant.PhoneNumber;
            View.Fax = restaurant.Fax;
            View.Email = restaurant.Email;
            View.Website = restaurant.Website;
            View.TaxCode = restaurant.TaxCode;
            View.IsActive = restaurant.IsActive;
            View.IsAgencies = restaurant.IsAgencies;
        }

        public int Save()
        {
            var restaurant = new RestaurantModel
            {
                RestaurantID = View.RestaurantID,
                RestaurantCode = View.RestaurantCode,
                RestaurantName = View.RestaurantName,
                Address = View.Address,
                PhoneNumber = View.PhoneNumber,
                Fax = View.Fax,
                Email = View.Email,
                Website = View.Website,
                TaxCode = View.TaxCode,
                IsActive = View.IsActive,
                IsAgencies = View.IsAgencies
            };

            if (View.RestaurantID == null)
                return Model.AddRestaurant(restaurant);
            else
                return Model.UpdateRestaurant(restaurant);
        }

        public int Delete(string restaurantId)
        {
            return Model.DeleteRestaurant(restaurantId);
        }
    }
}
